<template>
  <div>
    <el-page-header @back="remove" :content="pageTitle"></el-page-header>
    <el-divider content-position="left">
      <h3>面试结果</h3>
    </el-divider>
    <el-card class="box-card">
      <el-form label-position="right" label-width="80px" :model="dataForm" :rules="rules" ref="ruleForm">
        <el-form-item label="是否签到" class="wds-frame-form-item" label-width="120px" prop="signIn">
          <el-select v-model="dataForm.signIn" placeholder="请选择是否签到">
            <el-option
              v-for="item in signInStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="签到时间" class="wds-frame-form-item" label-width="120px"
                      prop="signInTime"
                      v-if="signInVisible === dataForm.signIn">
          <el-date-picker
            v-model="dataForm.signInTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择签到时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最低薪资" class="wds-frame-form-item" label-width="120px"
                      prop="minPay"
                      v-if="signInVisible === dataForm.signIn">
          <el-select v-model="dataForm.minPay" placeholder="请选择最低薪资">
            <el-option
              v-for="item in minPay"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="面试评分" class="wds-frame-form-item" label-width="120px"
                      prop="interviewScore"
                      v-if="signInVisible === dataForm.signIn">
          <el-select v-model="dataForm.interviewScore" placeholder="面试评分">
            <el-option
              v-for="item in scoreList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="面试结果状态" class="wds-frame-form-item" label-width="120px"
                      prop="interviewStatus"
                      v-if="signInVisible === dataForm.signIn">
          <el-select v-model="dataForm.interviewStatus" placeholder="请选择是否通过">
            <el-option
              v-for="item in interviewStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="wds-frame-form-item">
          <el-button type="primary" @click="submitForm('ruleForm')" class="button">录入</el-button>
          <el-button @click="resetForm('ruleForm')" class="button">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>


<script>
  export default {
    data(){
      return {
        signInVisible: 1,
        signInStatus:[{
          value: 0,
          label: '未签到'
        },{
          value: 1,
          label: '已签到'
        }],
        scoreList: [{
          value: 59,
          label: '差'
        },{
          value: 75,
          label: '一般'
        },{
          value: 85,
          label: '良好'
        },{
          value: 95,
          label: '优秀'
        }],
        interviewStatus:[{
          value: 0,
          label: '未通过'
        },{
          value: 1,
          label: '已通过'
        }],
        minPay:[{
          value: 2500,
          label: '2500'
        },{
          value: 3000,
          label: '3000'
        }],
        interviewId: '',
        interviewName: '',
        station: '',
        pageTitle: '',
        dataForm: {
          signIn: '',
          signInTime: '',
          minPay: '',
          interviewScore: '',
          interviewStatus: '',
        },
        rules:{
          signIn:[{required: true, message: '请选择是否签到', trigger: 'blur'}],
          signInTime:[{required: true, message: '请选择签到时间', trigger: 'blur'}],
          minPay:[{required: true, message: '请选择最低薪资', trigger: 'blur'}],
          interviewScore:[{required: true, message: '请选择面试评分', trigger: 'blur'}],
          interviewStatus:[{required: true, message: '请选择面试结果状态', trigger: 'blur'}]
        }
      }
    },
    methods: {
      remove () {
        this.$emit('remove');
      },
      init(id){
        console.log(id,"xx")
        this.interviewId = id;
        console.log(this.interviewId)
        this.getInterviewRecords(id)
      },
      submitForm(ruleForm) {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/interview/interviewRecords/addInterviewResult`),
              method: 'post',
              data: this.$http.adornData({
                'interviewId': this.interviewId || undefined,
                'signIn': this.dataForm.signIn,
                'signInTime': this.dataForm.signInTime,
                'minPay': this.dataForm.minPay,
                'interviewScore': this.dataForm.interviewScore,
                'interviewStatus': this.dataForm.interviewStatus
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: data.msg,
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          } else {
            console.log('error submit!!')
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      // 通过Id查询当前的面试记录
      getInterviewRecords(id){
        this.$http({
          url: this.$http.adornUrl(`/interview/interviewRecords/info/${this.interviewId}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            // 数据回显
            this.dataForm.signIn = data.interviewRecords.signIn
            this.dataForm.signInTime = data.interviewRecords.signInTime
            this.dataForm.minPay = data.interviewRecords.minPay
            this.dataForm.interviewScore = data.interviewRecords.interviewScore
            this.dataForm.interviewStatus = data.interviewRecords.interviewStatus
            this.interviewName = data.interviewRecords.name
            this.station = data.interviewRecords.station
            this.pageTitle = '录入面试结果' + ':' + this.interviewName + ':' + this.station
          }
        })
      }

    }
  }
</script>



<style >
.box-card {
  margin-top: 30px;
  width: auto;
  height: 551px;
}
.wds-frame-form-item{
  max-height: 40px;
  padding-top: 6px;
  padding-left: 4px;
  line-height: 20px !important;
  color: #054999;
}
.button{
  margin-top: 15px;
  margin-left: 50px;
}
</style>
